package hh.util.time;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

/**
 * @author huanghuai
 * @date 2020/9/30
 */
public class MyCalenderTest {

    public static void main(String[] args) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");
        format.setTimeZone(TimeZone.getDefault());
        Date date = format.parse("1970-01");

        long count = 10000_10000 * 1;
        new Thread(() -> my(count)).start();
        new Thread(() -> calendar(count)).start();


    }

    private static void calendar(long count) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
            yearMonth();
        }
        System.out.println("calendar=" + (System.currentTimeMillis() - start));
    }

    private static void my(long count) {
        long start = System.currentTimeMillis();
        for (int i = 0; i < count; i++) {
//             MyCalender.yearMonth(start);
        }
        System.out.println("my=" + (System.currentTimeMillis() - start));
    }

    /**
     * //      * 获取当前年月
     * //
     */
    public static String yearMonth() {
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1;
        return year + "-" + month;
    }
}
